/**
 * @author MADSTONE_L
 */

Ext.ns('Sys', 'Sys.main', 'Sys.config', 'Sys.User.Config', 'Sys.User.Right',
		'Sys.date', 'Sys.data', 'Sys.ux', 'Sys.app', 'Sys.url', 'Sys.common',
		'Sys.fn', 'Ext.ux');
Ext.apply(Sys, {
	version : '0.1',
	author : 'madStone_l',
	animEl : 'southPanel',
	date : {
		Now : new Date()
	},
	rootPath : window.document.location.href.substring(0,
			window.document.location.href.lastIndexOf('/'))
			+ '/',
	versionDetail : {
		major : 3,
		minor : 3,
		patch : 0
	},
	getRight : function(classID, bit, msg) {
		var rightFlags = '';
		Ext.each(Sys.User.Right.modules, function(v, i, a) {
					if (v.ClassID == classID) {
						rightFlags = v.RightFlags;
						return false;
					}
				});
		if (!Ext.isEmpty(rightFlags) && rightFlags.charAt(bit - 1) == 1) {
			return true;
		}
		if (!Ext.isEmpty(msg))
			Ext.Msg.showError('您没有' + msg + '权限，不能进行此项操作！')
		return false;

	},
	config : function(paramCode) {
		var paramValue;
		Ext.each(Sys.params, function(v) {
					if (v.ParamCode == paramCode) {
						paramValue = v.ParamValue;
						return false;
					}
				});
		if (!isNaN(paramValue))
			return parseFloat(paramValue);
		return paramValue;
	},
	getIconImg : function(img) {
		return "<img src = 'resources/images/icons/"
				+ img
				+ "' width='16' height='16' style='margin-right: 4px;float: left;' />";
	},
	Renderer : {
		combo : function(combo) {
			return function(value) {
				var record = combo.findRecord(combo.valueField, value);
				return record
						? record.get(combo.displayField)
						: combo.valueNotFoundText;
			}
		},
		bool : function(v) {
			return (v == 1 || v == true || v == 'True') ? Sys
					.getIconImg('tick.png') : null;
		},
		money : function(v) {
			return Ext.util.Format.usMoney(v).replace('$', '￥');
		},
		sex : function(v) {
			if (v == 1 || v == '男')
				return Sys.getIconImg('user_suit.png') + '男';
			if (v == 0 || v == '女')
				return Sys.getIconImg('user_female.png') + '女';

		},
		valid : function(v) {
			return (v == 1 || v == true || v == 'True')
					? "<span style = 'color: green;'>有效</span>"
					: "<span style = 'color: red;'>禁用</span>";
		},

		orderStatus : function(v) {
			var n = '';
			var img = '';
			if (Ext.isEmpty(v))
				return v;
			if (isNaN(v) || v >= Sys.data.CoreOrderStatus.length) {
				n = '未知'
				img = 'base/question-shield.png';
			} else {
				var obj = Sys.data.CoreOrderStatus[v];
				n = obj.StatusName;
				img = obj.IconUrl;
			}
			return Sys.getIconImg(img) + n;
		},
		SaleType : function(v) {
			if (Ext.isEmpty(v))
				return v;
			var saleType = Sys.fn.getSaleType(v);
			if (saleType)
				return saleType.TypeName;
			return '未知';
		}
	},

	data : {
		Store : {
			sex : [[true, "男"], [false, "女"]],
			valid : [[true, "有效"], [false, "禁用"]],
			orderStatus : function() {
				var array = [];
				Ext.each(Sys.data.CoreOrderStatus, function(v) {
							if (v.IsEnabled)
								array
										.push(new Array(v.StatusFlag,
												v.StatusName));
						});
				return array;
			},
			SaleType : function() {
				var array = [];
				Ext.each(Sys.data.CoreSaleType, function(v) {
							if (v.IsEnabled)
								array.push(new Array(v.TypeFlag, v.TypeName));
						});
				return array;
			},
			themes : ['8bb7f3', '8b98f3', '9c8bf3', 'bb8bf3', 'da8bf3',
					'f38beb', 'f38bcc', 'f38bad', 'f38b8e', 'f3a68b', 'f3c58b',
					'f3e58b', 'e1f38b', 'c2f38b', 'a3f38b', '8bf392', '8bf3b1',
					'8bf3d0', '8bf3ef', '8bd7f3', 'bfbfbf'],
			doGetDateField : function(n) {
				return {
					name : n,
					type : 'date',
					dateFormat : 'M$'
				}
			}
		},
		SetRecord : function(r, d) {
			for (var k in d) {
				r.set(k, d[k]);
			}
			return r;
		}
	},
	Msg : {
		showInfo : function(htmlMsg) {
			new Ext.ux.Notification({
						autoHide : true,
						hideDelay : 2000
					}).showMessage('系统提示', htmlMsg, true);
		},
		showWarning : function(htmlMsg) {
			new Ext.ux.Notification({
						autoHide : true,
						hideDelay : 2000
					}).showWarning('操作警告', htmlMsg);
		}
	}
});
